// FSDrives.h

#ifndef __FS_DRIVES_H
#define __FS_DRIVES_H

//It is used in only RootFolder and PanelFolderChange (check it)

#include "IFolder.h"

#include <vector>

namespace Common
{
namespace FileSystem
{

struct CDriveInfo
{
	UINT64    DriveSize;
	UINT64    FreeSpace;
	UINT64    ClusterSize;
	UINT      DriveType;
	CString   Name;
	CString   FullSystemName;	
	// CString Type;
	CString   VolumeName;
	CString   FileSystemName;
	bool      KnownSizes;
	
	CDriveInfo() {}
	CDriveInfo(const CDriveInfo &obj) :
		Name(obj.Name),
		FullSystemName(obj.FullSystemName),
		KnownSizes(obj.KnownSizes),
		DriveSize(obj.DriveSize),
		FreeSpace(obj.FreeSpace),
		ClusterSize(obj.ClusterSize),
		// Type(obj.Type),
		VolumeName(obj.VolumeName),
		FileSystemName(obj.FileSystemName),
		DriveType(obj.DriveType)
	{
	}
	CString GetDeviceFileIoName() const;
};

class ATL_NO_VTABLE CFSDrives:
	public IFolderFolder,
	public IFolderOperations,
	public IFolderGetSystemIconIndex,
	public CComObjectRootEx<CComSingleThreadModel>
{
	std::vector<CDriveInfo> _drives;
	bool _volumeMode;

	HRESULT BindToFolderSpec(const wchar_t* name, IFolderFolder** resultFolder);
	CString GetExt(int index) const;
	HRESULT GetLength(int index, UINT64 &length) const;
public:

	BEGIN_COM_MAP(CFSDrives)
	COM_INTERFACE_ENTRY(IFolderFolder)
	COM_INTERFACE_ENTRY(IFolderOperations)
	COM_INTERFACE_ENTRY(IFolderGetSystemIconIndex)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		//Separate init from object construction
		//Init();
		return S_OK;
	}

	void FinalRelease()
	{

	}

	//INTERFACE FolderFolder
	STDMETHOD(LoadItems)() ;
	STDMETHOD(GetNumberOfItems)(UINT32* numItems) ;
	STDMETHOD(GetProperty)(UINT32 itemIndex, PROPID propID, PROPVARIANT* value) ;
	STDMETHOD(BindToFolder)(UINT32 index, IFolderFolder** resultFolder) ;
	STDMETHOD(BindToFolder)(const wchar_t* name, IFolderFolder** resultFolder) ;
	STDMETHOD(BindToParentFolder)(IFolderFolder** resultFolder) ;
	STDMETHOD(GetNumberOfProperties)(UINT32* numProperties) ;
	STDMETHOD(GetPropertyInfo)(UINT32 index, BSTR* name, PROPID* propID, VARTYPE* varType) ;
	STDMETHOD(GetFolderProperty)(PROPID propID, PROPVARIANT* value) ;

	//INTERFACE FolderOperations
	STDMETHOD(CreateFolder)(const wchar_t* name, IProgress* progress) ;
	STDMETHOD(CreateFile)(const wchar_t* name, IProgress* progress) ;
	STDMETHOD(Rename)(UINT32 index, const wchar_t* newName, IProgress* progress) ;
	STDMETHOD(Delete)(const UINT32* indices, UINT32 numItems, IProgress* progress) ;
	STDMETHOD(CopyTo)(const UINT32* indices, UINT32 numItems,
					  const wchar_t* path, IFolderOperationsExtractCallback* callback) ;
	STDMETHOD(MoveTo)(const UINT32* indices, UINT32 numItems,
					  const wchar_t* path, IFolderOperationsExtractCallback* callback) ;
	STDMETHOD(CopyFrom)(const wchar_t* fromFolderPath,
						const wchar_t** itemsPaths, UINT32 numItems, IProgress* progress) ;
	STDMETHOD(SetProperty)(UINT32 index, PROPID propID, const PROPVARIANT* value, IProgress* progress) ;

	STDMETHOD(GetSystemIconIndex)(UINT32 index, INT32* iconIndex);

	HRESULT Init(bool volMode = false)
	{
		_volumeMode = volMode;
		return LoadItems();
	}
};

}
}

#endif
